<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
* {
	padding: 0;
	margin: 0;
}

body,html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#tabtop {
	line-height: 31px;
	background: url("/admin/templates/images/map_top_bg.png") repeat;
	font-size: 12px;
	color: #343434;
}

#tabtop span {
	float: left;
	line-height: 31px;
	display: block;
}

#tabtop span.dob {
	padding-left: 7px;
}

#tabtop span.dob a {
	background: url("/admin/templates/images/yuncheng_a.png") no-repeat left
		center;
}

#tabtop span.dob a.ok {
	color: #3a3;
}

#tabtop span.dob a.on {
	color: #ef4f4f;
}

#tabtop span a {
	padding: 0 16px 0 8px;
	color: #343434;
	text-decoration: none;
}

#tabtop span.bd a {
	border-right: 1px solid #ccc;
	padding: 0 12px;
}

.position {
	vertical-align: text-bottom;
	margin-right: 5px;
	width: 9px;
}

.warring {
	color: #f00;
	padding: 0 12px;
	font-weight: bold;
}

.warring i {
	font-style: normal;
	float: left;
}

#tabtop span.warring a {
	color: #f00;
	display: block;
	float: left;
}

#allmap {
	width: 100%;
}
</style>

<script type="text/javascript">
        //<!CDATA[
        var SITE_URL = "{$site_url}";
        var REAL_SITE_URL = "{$real_site_url}";
        var REAL_BACKEND_URL = "{$real_backend_url}";
        var car_code = "{$vhc_code}";
        //]]>
    </script>
    <script src="http://webapi.amap.com/maps?v=1.3&key=78634dd0056201e14a509d5765eb7ce6"></script>
<script type="text/javascript" src="{lib file=jquery.js}"
	charset="utf-8"></script>
<title>车辆轨迹 </title>
</head>
<body class="page">
	<div id="tabtop">
		<span class="bd"> <a href="javascript:void(0);"
			onclick="endselect()" style="font-weight: bold;">{$bill.wm_code}&nbsp;[<font
				style="color: red;">{$bill.wm_stauts}</font>]&nbsp;[{$bill.wm_type}]&nbsp;{$bill.wm_carrier}</a>
			<a href="javascrip:void(0);" onclick="startselect()"><img
				src="/admin/templates/images/position.png" class="position" alt="">起点</a>
		</span> <span class="bd"> <a href="javascrip:void(0);"
			onclick="endselect();">{$bill.wm_vhc_code}{$bill.wm_driver}{$bill.wm_driver_tel}&nbsp;<img
				src="/admin/templates/images/position.png" class="position" alt="">位置</a>
		</span> <span class="dob">
			<!--
        运程：
        <a href="javascript:void(0);" class="haul on">1背空箱</a>
        <a href="javascript:void(0);" class="haul">2装箱</a>
        <a href="javascript:void(0);" class="haul">2装箱</a>--> </span> <span
			class="warring">
			<!--
        <i>异常：</i>
        <a href="javascript:void(0);" class="exception">临时加油</a>
        <a href="javascript:void(0);" class="exception">堵车</a>
        <a href="javascript:void(0);" class="exception">车辆抛锚</a>--> </span> <span><input
			type="checkbox" id="showcar" checked="checked" /><label for="showcar">显示车辆</label> <a onclick="map.setFitView()" style="cursor: hand;">查看全程</a>
		</span>
		<div style="clear: both;"></div>
	</div>
	<div id="allmap"></div>
</body>
</html>

<script type="text/javascript">
    function mapcenter(lng, lat) {
        map.clearInfoWindow();
        map.setCenter(new AMap.LngLat(lng, lat));
    }
    function mapcenterbd(lng, lat) {
        //百度转高德
        gdpoint = gcj_encrypt(lng, lat);
        map.clearInfoWindow();
        map.setCenter(new AMap.LngLat(gdpoint.lng, gdpoint.lat));
    }
    function ispoint(h_lng, h_lat) {
        if (h_lng != undefined && h_lng != null && h_lng != "" && h_lng != "0" && h_lat != undefined && h_lat != null && h_lat != "" && h_lat != "0"&&parseInt(h_lng)>0&&parseInt(h_lat)>0) {
            return true;
        }
        return false;
    }

    PI = 3.14159265358979324;
    x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    function bd_decrypt(bd_lon, bd_lat) {
    	
    	
//         x = bd_lon - 0.0065;
//         y = bd_lat - 0.006;
//         z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
//         theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
//         gg_lon = z * Math.cos(theta);
//         gg_lat = z * Math.sin(theta);
    }
    
    function transformLat(x, y){
    	  var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
          ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
          ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
          ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
          return ret;
    }
    
    function transformLon(x, y){
    	var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
        return ret;
  }
    
    function delta(lat, lon){
   	    var a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
        var ee = 0.00669342162296594323; //  ee: 椭球的偏心率。
        var dLat = this.transformLat(lon - 105.0, lat - 35.0);
        var dLon = this.transformLon(lon - 105.0, lat - 35.0);
        var radLat = lat / 180.0 * this.PI;
        var magic = Math.sin(radLat);
        magic = 1 - ee * magic * magic;
        var sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
        dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
        return {'lat': dLat, 'lon': dLon};
   }
   function gcj_encrypt(gcjLon,gcjLat){
   	 var d = delta(gcjLat, gcjLon);
   	 return new AMap.LngLat(parseFloat(gcjLon) + parseFloat(d.lon), parseFloat(gcjLat) + parseFloat(d.lat))
   }

    var EARTH_RADIUS = 6378137.0; //单位M
    var PI = Math.PI;

    function getRad(d){
        return d*PI/180.0;
    }

    /**
     * approx distance between two points on earth ellipsoid
     * @param {Object} lat1
     * @param {Object} lng1
     * @param {Object} lat2
     * @param {Object} lng2
     */
    function getFlatternDistance(lat1,lng1,lat2,lng2){
        var f = getRad((lat1 + lat2)/2);
        var g = getRad((lat1 - lat2)/2);
        var l = getRad((lng1 - lng2)/2);

        var sg = Math.sin(g);
        var sl = Math.sin(l);
        var sf = Math.sin(f);

        var s,c,w,r,d,h1,h2;
        var a = EARTH_RADIUS;
        var fl = 1/298.257;

        sg = sg*sg;
        sl = sl*sl;
        sf = sf*sf;

        s = sg*(1-sl) + (1-sf)*sl;
        c = (1-sg)*(1-sl) + sf*sl;

        w = Math.atan(Math.sqrt(s/c));
        r = Math.sqrt(s*c)/w;
        d = 2*w*a;
        h1 = (3*r -1)/2/c;
        h2 = (3*r +1)/2/s;

        return d*(1 + fl*(h1*sf*(1-sg) - h2*(1-sf)*sg));
    }


    map = new AMap.Map("allmap", {
        resizeEnable: true,
        zoom: 12,
    });
    map.plugin(["AMap.Scale"],function(){
        var scale = new AMap.Scale();
        map.addControl(scale);
    });
    map.plugin(["AMap.ToolBar"],function(){
        //加载工具条
        var tool = new AMap.ToolBar();
        map.addControl(tool);
    });

    if(ispoint('{$bill.wm_startlng}','{$bill.wm_startlat}'))
    {
        var ptend = new AMap.LngLat('{$bill.wm_startlng}','{$bill.wm_startlat}');
        if (vpend != null) {
            map.setCenter(ptend);
        }
    }
    var $loadingToast = $('#loadingToast');
    $(this).ajaxStart(function () {
//        if ($loadingToast.css('display') != 'none') {
//            return;
//        }
//        $loadingToast.show();
    }).ajaxStop(function () {
//        $loadingToast.hide();
    });
    //临时覆盖层
    var vmapover = null;
    //车辆标志
    var vmapcar = null;
    //起点标志
    var vmapstart = null;
    //最新点时间
    var vpendtime = "";
    //最新点数据
    var vpend = null;
    //起点数据
    var vpstart = null;
    //所有点数据
    var vp = [];
    //最近取回百度点
    var vptemp = [];
    //运程点信息
    var vhaul = [];
    //异常点信息
    var vexception = [];
    
    var makerall=[];
    var vpPolylineColor = [];
    
    var l=true;
    var png="";
    
    var lngoffset=0.0005;
    function resetposition(marker){
    	var f=false;
    	if(makerall.length>0){
    		for(var i=0;i<makerall.length;i++){
    			var mlng=marker.point.lng;
    			var mlat=marker.point.lat;
    			var lng=makerall[i].point.lng;
    			var lat=makerall[i].point.lat;
    			if(getjuli(mlat,mlng,lat,lng)*1000<=5){
    				f=true;
    				marker.setPosition(new BMap.Point(mlng+lngoffset,mlat));   				
    			}
    		}
    	}
    	if(!f){
			makerall.push(marker);
    	}else{
    		resetposition(marker);
    	}
    }
    
    function startselect(){
        if(vpstart!=null){
            mapcenter(vpstart.lng, vpstart.lat);
        }
        else{
            alert('车辆暂时未传回位置信息');
        }
    }
    function endselect(){
        if(vpend!=null){
            mapcenter(vpend.lng, vpend.lat);
        }
        else{
            alert('车辆暂时未传回位置信息');
        }
    }
    function hualselect() {
        if (vhaul.length > 0)
            haulhtml = '运程：';
        else
            haulhtml = '';
        for (var hi = 0; hi < vhaul.length; hi++) {
            clickhtml = "";
            if (vhaul[hi].h_finished < 2) {
                if (ispoint(vhaul[hi].h_lng, vhaul[hi].h_lat)) {
                    clickhtml = 'onclick="mapcenter(' + vhaul[hi].h_lng + ',' + vhaul[hi].h_lat + ')"';
                }
            }
            else {
                if (ispoint(vhaul[hi].h_finished_lng, vhaul[hi].h_finished_lat)) {
                    clickhtml = 'onclick="mapcenter(' + vhaul[hi].h_finished_lng + ',' + vhaul[hi].h_finished_lat + ')"';
                }
            }
            //vhaul[hi].h_order + ':' +
            haulhtml += '<a href="javascript:void(0);" '+clickhtml+' class="' + (vhaul[hi].h_finished == '2' ? "ok" : (vhaul[hi].h_finished == '1' ? "on" : "")) + '">' + vhaul[hi].h_short_name + '</a>';
        }
        $(".dob").html(haulhtml);
    }
    function exceptionselect() {
        if (vexception.length > 0)
            exceptionhtml = '<i>异常：</i>';
        else
            exceptionhtml = '';
        for (var hi = 0; hi < vexception.length; hi++) {
            clickhtml = "";
            if (ispoint(vexception[hi].e_lng, vexception[hi].e_lat)) {
                clickhtml = 'onclick="mapcenter(' + vexception[hi].e_lng + ',' + vexception[hi].e_lat + ')"';
            }
            stylehtml='';
            if(vexception[hi].e_staus=='已处理')
            {
                stylehtml='style="color:#F60"'
            }
            exceptionhtml += '<a href="javascript:void(0);" '+clickhtml+' '+stylehtml+'>' + vexception[hi].e_type + '</a>';
        }
        $(".warring").html(exceptionhtml);
    }
    //异常点击
    function vmapexceptionclick(event) {
        infowin = new AMap.InfoWindow({
            autoMove: true,
            size:new AMap.Size(730,510),
            content: "<iframe style='border:none;width:100%;height:500px' src='" + SITE_URL + "/index.php?app=exception&act=view&id=" + event.target.tid + "'>"
        });
        infowin.open(map, new AMap.LngLat(event.lnglat.lng, event.lnglat.lat));
    }
    //运程点击
    function vmaphaulclick(event) {
        infowin = new AMap.InfoWindow({
            autoMove: true,
            size:new AMap.Size(730,510),
            content: "<iframe style='border:none;width:100%;height:500px' src='" + SITE_URL + "/index.php?app=haul&act=view&id=" + event.target.tid + "'>"
        });
        infowin.open(map, new AMap.LngLat(event.lnglat.lng, event.lnglat.lat));
    }
    //车辆点击
    function vmapcarclick(event) {
        infowin = new AMap.InfoWindow({
            autoMove: true,
            size:new AMap.Size(730,510),
            content: "<iframe style='border:none;width:100%;height:500px' src='" + SITE_URL + "/index.php?app=map&act=view&id=" + event.target.tid + "'>"
        });
        infowin.open(map, new AMap.LngLat(event.lnglat.lng, event.lnglat.lat));
    }
    var infowinpoint = new AMap.InfoWindow({autoMove: true});
    //点数据获取和处理
    function getCarLine() {

        console.log(vpendtime);

        $.ajax({
            type: "GET",
            url: REAL_SITE_URL + "/index.php",
            data: {app: 'map', act: 'ajax_haul', id: '{$id}'},
            dataType: 'json',
            success: function (data) {
                haultemp = data;
                $.each(haultemp, function (commentIndex, haul) {
                    vflag = false;
                    $.each(vhaul, function (vhaulIndex, vhaulin) {
                        if (haul.h_tid == vhaulin.h_tid) {
                        vflag = true;
                        }
                    });
                    if (!vflag) {
                        if(ispoint(haul.h_finished_lng, haul.h_finished_lat)) {
                            //添加运程完成点//百度转高德
                            gdpoint = gcj_encrypt(haul.h_finished_lng, haul.h_finished_lat);
                            haul.h_finished_lat = gdpoint.lat;
                            haul.h_finished_lng = gdpoint.lng;
                            haulpoint = new AMap.LngLat(haul.h_finished_lng, haul.h_finished_lat);

                            if (haul.h_mapimage!=null&&haul.h_mapimage != "") {
                                vmaphaul = new AMap.Marker({position:haulpoint
                                    , icon: new AMap.Icon({
                                        size:new AMap.Size(19,33),//图标大小
                                        image: SITE_URL + haul.h_mapimage
                                    }),label: {content:haul.h_short_name + " " + haul.h_finished_date,offset:{x:20,y:0}}
                                });
                            }
                            else {
                                vmaphaul = new AMap.Marker({position:haulpoint
                                    , icon: new AMap.Icon({
                                        size:new AMap.Size(19,33),//图标大小
                                        image: "../images/mark_bs.png"
                                    }),label: {content:haul.h_short_name + " " + haul.h_finished_date,offset:{x:20,y:0}}
                                });
                            }
                            vmaphaul.id = "haul_" + haul.h_tid;
                            vmaphaul.tid = haul.h_tid;
                            AMap.event.addListener(vmaphaul, "click", function(e) {
                                vmaphaulclick(e);
                            });
                            //resetposition(vmaphaul);
                            vmaphaul.setMap(map);           // 将标注添加到地图中
                        }
                        else{
                            //添加运程定义点
                            if(ispoint(haul.h_lng, haul.h_lat)) {
                                //百度转高德
                                gdpoint = gcj_encrypt(haul.h_lng, haul.h_lat);
                                haul.h_lat = gdpoint.lat;
                                haul.h_lng = gdpoint.lng;
                                haulpoint = new AMap.LngLat(haul.h_lng, haul.h_lat);
                                if (haul.h_mapimage!=null&&haul.h_mapimage != "") {
                                    vmaphaul = new AMap.Marker({position:haulpoint
                                        , icon: new AMap.Icon({
                                            size:new AMap.Size(19,33),//图标大小
                                            image: SITE_URL + haul.h_mapimage
                                        }),label: {content:haul.h_short_name + " 运程",offset:{x:20,y:0}}
                                    });
                                }
                                else {
                                    vmaphaul = new AMap.Marker({position:haulpoint
                                        , icon: new AMap.Icon({
                                            size:new AMap.Size(19,33),//图标大小
                                            image: "../images/mark_bs.png"
                                        }),label: {content:haul.h_short_name + " 运程",offset:{x:20,y:0}}
                                    });
                                }
                                //resetposition(vmaphaul);
                                vmaphaul.setMap(map);              // 将标注添加到地图中

                            }
                        }
                        vhaul.push(haul);
                    }
                });
                hualselect();

                for(var colori=0;colori<haultemp.length;colori++){
                    if(haultemp[colori].h_changecolor==""){
                        haultemp[colori].h_changecolor="red";
                    }
                }


                $.ajax({
                    type: "GET",
                    url: REAL_SITE_URL + "/index.php",
                    data: {app: 'map', act: 'gpsinfo', id: '{$id}'},
                    dataType: 'json',
                    success: function (data) {

                        vptemp = [];
                        vpPolyline = [];
                        vptempval=[];
                        vpcolori=0;
                        $.each(data, function (commentIndex, vpoints) {
                            //百度转高德
                            gdpoint = gcj_encrypt(vpoints.lng, vpoints.lat);
                            vpoints.lat1 = vpoints.lat;
                            vpoints.lng1 = vpoints.lng;
                            vpoints.lat = gdpoint.lat;
                            vpoints.lng = gdpoint.lng;
                            vp.push(vpoints);
                            vptemp.push([vpoints.lng, vpoints.lat]);

                            //不同运程 色的线
                            vptempval.push([vpoints.lng, vpoints.lat]);
                            console.log(vpcolori);
                            console.log(haultemp[vpcolori]);
                            if(haultemp.length>vpcolori&&vpcolori>=0&&vpoints.time>=haultemp[vpcolori].h_finished_date){
                                vpPolyline.push(vptempval);
                                vpPolylineColor.push(haultemp[vpcolori]);
                                vptempval=[];
                                vptempval.push([vpoints.lng, vpoints.lat]);
                                if(vpcolori<haultemp.length-1)
                                    vpcolori++;
                            }

                            if (vpstart == null) {
                                vpstart = vpoints;
                                mapcenter(vpstart.lng, vpstart.lat);
                            }
                            vpend = vpoints;
                        });


                        if(vptempval.length>0){
                            vpPolyline.push(vptempval);
                            if(haultemp[vpcolori])
                                vpPolylineColor.push(vhaul[vpcolori]);
                            else
                                vpPolylineColor.push({'h_changecolor':'red'});
                        }
                        if(vpPolyline.length>0){
                            $.each(vpPolyline,function(index,vptemp){
                                vmapover = new AMap.Polyline({
                                    path: vptemp,
                                    strokeColor: vpPolylineColor[index].h_changecolor,
                                    strokeWeight: 4,
                                    strokeOpacity: 1
                                });
                                AMap.event.addListener(vmapover, "click", function(e) {
                                    mapclick(e);
                                });//
                                vmapover.setMap(map);
                            });
                        }
						
                        if(vmapover!=null&&vmapover!=undefined){
                        AMap.event.addListener(vmapover, "click", function (e) {
                            mapclick(e);
                        });//
                        }
                        if (vpend != null) {
                            var ptend = new AMap.LngLat(vpend.lng, vpend.lat);
                            if (vmapcar == null&&$("#showcar").attr("checked")==true) {
                                carurl='../images/car.png';
                                vmapcar = new AMap.Marker({
                                    position: [vpend.lng, vpend.lat]
                                    ,icon: new AMap.Icon({
                                        size:new AMap.Size(15,32),//图标大小
                                        image:carurl
                                    }),label: {content:car_code+' 速度'+vpend.speed+'<br/>'+vpend.time,offset:{x:20,y:0}},
                                    //这里用/img/loc.png图片的left:18;top:38指向坐标
                                    offset: new AMap.Pixel(-8,-16)
                                    , angle: vpend.direction
                                });
                                vmapcar.tid = {$id};
                                AMap.event.addListener(vmapcar, "click", function(e) {
                                    vmapcarclick(e);
                                });
                                vmapcar.setMap(map);              // 将标注添加到地图中
                                map.setCenter(new AMap.LngLat(vpend.lng, vpend.lat));
                            }
                            else {
                                vmapcar.setPosition(ptend);
                            }
                            if (vpend != null & vpend.time != undefined) {
                                vpendtime = vpend.time;
                            }
                        }
                        if (vpstart != null) {
                            var ptstart = new AMap.LngLat(vpstart.lng, vpstart.lat);
                            if (vmapstart == null) {
                                var ptstart = new AMap.LngLat(vpstart.lng, vpstart.lat);
                                if (vmapstart == null) {
                                    vmapstart = new AMap.Marker({
                                        position: ptstart
                                        , icon: new AMap.Icon({
                                            image: "../images/start.png"
                                        })
                                    });

                                    vmapstart.setMap(map);              // 将标注添加到地图中
                                }
                            }
                        }
                    }
                });

            }
        });


        $.ajax({
            type: "GET",
            url: REAL_SITE_URL + "/index.php",
            data: {app: 'map', act: 'ajax_exception', id: '{$id}'},
            dataType: 'json',
            success: function (data) {
                exceptiontemp = data;
                $.each(exceptiontemp, function (commentIndex, exception) {
                    vflag = false;
                    $.each(vexception, function (vexceptionIndex, vexceptionin) {
                        if (exception.e_tid == vexceptionin.e_tid) {
                            vflag = true;
                        }
                    });
                    if (!vflag) {
                        if(ispoint(exception.e_lng, exception.e_lat)) {
                            //百度转高德
                            gdpoint = gcj_encrypt(exception.e_lng, exception.e_lat);
                            exception.e_lat = gdpoint.lat;
                            exception.e_lng = gdpoint.lng;
                            vexception.push(exception);
                            exceptionpoint = new AMap.LngLat(exception.e_lng, exception.e_lat);

                            vmapexception = new AMap.Marker({position:exceptionpoint
                                , icon: new AMap.Icon({
                                    size:new AMap.Size(19,33),//图标大小
                                    image: "../images/mark_error.png"
                                }),label: {content:exception.e_type + " " + exception.e_date,offset:{x:20,y:0}}
                            });

                            vmapexception.tid = exception.e_tid;
                            AMap.event.addListener(vmapexception, "click", function(e) {
                                vmapexceptionclick(e);
                            });

                            //resetposition(vmapexception);
                            vmapexception.setMap(map);           // 将标注添加到地图中
                        }
                    }
                });
                exceptionselect();
            }
        });

        AMap.event.addListener(map, "click", function (e) {
            mapclick(e);
        });//

    }


    function mapclick(e){
        gfd = 8000, gfdtemp = 0, gfdcur = null;
        $.each(vp, function (vpindex, vpcur) {
            gfdtemp = (getFlatternDistance(e.lnglat.lat, e.lnglat.lng, vpcur.lat, vpcur.lng));
            if (gfdtemp < gfd) {
                gfdcur = vpcur;
                gfd = gfdtemp;
            }
        });
        if (gfdcur != null) {
            //mapcenter(gfdcur.lng, gfdcur.lat);
            AMap.service(["AMap.Geocoder"], function () {
                geocoder = new AMap.Geocoder();
                //返回地理编码结果
                geocoder.getAddress(new AMap.LngLat(gfdcur.lng, gfdcur.lat), function (status, result) {
                    //根据服务请求状态处理返回结果
                    if (status == 'error') {
                        infowinpoint.setContent("速度:" + gfdcur.speed + " 时间:" + gfdcur.time+"<br/>"+gfdcur.lng+","+gfdcur.lat);
                        infowinpoint.open(map, new AMap.LngLat(gfdcur.lng, gfdcur.lat));
                    }
                    if (status == 'no_data') {
                        infowinpoint.setContent("速度:" + gfdcur.speed + " 时间:" + gfdcur.time+"<br/>"+gfdcur.lng+","+gfdcur.lat);
                        infowinpoint.open(map, new AMap.LngLat(gfdcur.lng, gfdcur.lat));
                    }
                    else {
                        infowinpoint.setContent("" + result.regeocode.formattedAddress + result.regeocode.addressComponent.streetNumber + "<br/>速度:" + gfdcur.speed + " 时间:" + gfdcur.time+"<br/>"+gfdcur.lng1+","+gfdcur.lat1);
                        infowinpoint.open(map, new AMap.LngLat(gfdcur.lng, gfdcur.lat));
                    }
                });
            });
        }
    }
    function getjuli(ilat,ilng,nowlat,nowlng){
        ilat=parseFloat(ilat);
        ilng=parseFloat(ilng);
        c = 6378.138*2*Math.asin(Math.sqrt(Math.pow(Math.sin((ilat *Math.PI/180-nowlat*Math.PI/180)/2),2)+Math.cos(ilat+Math.PI/180)*Math.cos(nowlat*Math.PI/180)*Math.pow(Math.sin((ilng*Math.PI/180-nowlng*Math.PI/180)/2),2)));
        return parseFloat(c);
    }
    function winresize() {
        $("#allmap").height($(window).height() - $("#tabtop").height());
    }
    $(function () {
        try {
            winresize();
            $(window).resize(function () {
                winresize();
            });
            getCarLine();
            window.setInterval(getCarLine, 10000);
            
            $("#showcar").click(function(){
            	if(this.checked){
                    if (vpend != null) {
                        var ptend = new AMap.LngLat(vpend.lng, vpend.lat);
                        if (vmapcar == null&&$("#showcar").attr("checked")==true) {
                            carurl='../images/car.png';
                            vmapcar = new AMap.Marker({
                                position: [vpend.lng, vpend.lat]
                                ,icon: new AMap.Icon({
                                    size:new AMap.Size(15,32),//图标大小
                                    image:carurl
                                }),label: {content:car_code+' 速度'+vpend.speed+'<br/>'+vpend.time,offset:{x:20,y:0}},
                                //这里用/img/loc.png图片的left:18;top:38指向坐标
                                offset: new AMap.Pixel(-8,-16)
                                , angle: vpend.direction
                            });
                            vmapcar.tid = {$id};
                            AMap.event.addListener(vmapcar, "click", function(e) {
                                vmapcarclick(e);
                            });
                            vmapcar.setMap(map);              // 将标注添加到地图中
                            map.setCenter(new AMap.LngLat(vpend.lng, vpend.lat));
                        }
                        else {
                            vmapcar.setPosition(ptend);
                        }
                        if (vpend != null & vpend.time != undefined) {
                            vpendtime = vpend.time;
                        }
                    }
            	}else{
            		 if (vmapcar != null) {
            			 map.remove(vmapcar);
            			 vmapcar=null;
            		 }
            	}
            });
        }
        catch (e) {
            console.log(e);
        }
    });
</script>

